<template>
  <el-dialog title="销售出库单详情" :close-on-click-modal="false" :visible.sync="visible" fullscreen center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-divider content-position="left">单据信息</el-divider>
    <el-form :model="dataForm" ref="dataForm" label-width="90px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="单据编号" prop="takeBillId">
            <el-input v-model="dataForm.takeBillId" value="dataForm.takeBillId" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="单据日期" prop="createTime">
            <el-input v-model="dataForm.createTime" value="dataForm.createTime" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="制单人" prop="createUserName">
            <el-input v-model="dataForm.createUserName" value="dataForm.createUserName" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="销售部门">
            <el-select size="mini" v-model="dataForm.deptId" disabled>
              <el-option v-for="item in deptOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="发出仓位" prop="outStockName">
            <el-input v-model="dataForm.outStockName" value="dataForm.outStockName" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="memo">
            <el-input v-model="dataForm.memo" value="dataForm.memo" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-divider content-position="left">商品信息</el-divider>

    <div class="avue-crud">
      <el-table :data="dataList" border v-loading="dataListLoading">
        <el-table-column prop="goodsCode" label="商品代码"></el-table-column>
        <el-table-column prop="goodsName" label="商品名称"></el-table-column>
        <el-table-column prop="number" label="商品数量"></el-table-column>
        <el-table-column prop="spec" label="型号"></el-table-column>
        <el-table-column prop="costPrice" label="单位成本"></el-table-column>
        <el-table-column prop="costPriceTotal" label="成本合计"></el-table-column>
        <el-table-column prop="taxRate" label="税率"></el-table-column>
        <el-table-column prop="price" label="销售单价"></el-table-column>
        <el-table-column prop="priceTotal" label="销售金额"></el-table-column>
        <el-table-column prop="goodsBarcode" label="商品条码"></el-table-column>
      </el-table>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { getTakeInventoryInfo } from '@/api/eims/take-inventory/eimstakeinventory'
  import { getDeptInfoByDeptTypes } from '@/api/admin/dept'
  import { mapGetters } from "vuex"

  export default {
    data() {
      return {
        dataListLoading: false,
        visible: false,
        dataForm: {
          detailList: []
        },
        dataList: [],
        deptOptions: []
      };
    },
    created() {
      this.getSaleDeptList()
    },
    methods: {
      init(id) {
        this.dataForm.detailList = []
        this.dataList = []
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs["dataForm"].resetFields()
          if (this.dataForm.id) {
            this.dataListLoading = true
            getTakeInventoryInfo(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data
                this.dataList = response.data.data.detailList
              }else{
                this.$message.error(response.data.msg)
              }
              this.dataListLoading = false
            })
          }
        })
      },
      //支付状态类型转换
      receptionTypeChange(value) {
        let obj = {}
        obj = this.receptionTypeOptions.find(item => {
          if (item.value == value) {
            return item
          }
        })
        if (obj && obj.name) {
          return obj.name
        }
      },
      //获取销售部门列表
      getSaleDeptList() {
        let data = {
          deptTypes: [1]
        }
        getDeptInfoByDeptTypes(data).then(response => {
          if(response.data.code == '0'){
            this.deptOptions = response.data.data
          }else{
            this.$message.error(response.data.msg)
          }
        })
      }
    }
  };
</script>
<style>
  .el-divider__text,
  .el-link {
    font-size: 18px;
  }
</style>
